package com.activenetwork.smlite.testcase.events.createEvents.basics;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.activenetwork.schema.model.event.EventBasicType;
import com.activenetwork.smlite.page.event.EventDetailView.EventBasicSubview;
import com.activenetwork.smlite.snippet.EventsSnippet;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.RandomString;
import com.activenetwork.util.verification.gson.FailurePoint;

public class Basics016 extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(Basics016.class);
	private EventBasicType.Tag tag;
	
	@BeforeClass(alwaysRun = true)
	public void dataSetup(){
		tag = new EventBasicType.Tag();
		tag.setTagName("autotest-tag-duplicate-"+RandomString.generateRandomString(5));
		tag.setTagDesc("autotest-tag-duplicate-description");
		tag.setPrivate(false);
	}
	
	@Test
	public void Verify_duplicate_tag_can_not_be_allowed_to_create(){
		loginBusiness.login();
		
		// Create the tag for first time
		EventBasicSubview eventBasicSubview = EventsSnippet.gotoAddEventPage();
		
		eventBasicSubview = eventBasicSubview.setTag(tag);
		eventBasicSubview = eventBasicSubview.saveTag();
		
		// Create the same tag for second time
		eventBasicSubview = eventBasicSubview.setTag(tag);
		eventBasicSubview = eventBasicSubview.saveTag();
		
		// Verify the same tag will not display in the tag editbox again
		By by = By.cssSelector(".autotest-lookup-EventBasicSubview-event-tagsref .nexus-lookup>div[data-lookup-identifier]");
		List<WebElement> savedTags = webDriver.findElements(by);
		if(savedTags.size() > 1){
			EnvContext.failurePointTL.get().add(
					new FailurePoint(Basics016.class.getName(), 
					"Verify add duplicate tags", 
					"Duplicate tags can be created and saved"));
		}
		
		loginBusiness.logout();
	}
	
}
